package com.seckill.activemq;

import com.alibaba.fastjson.JSON;
import com.seckill.rabbitmq.MiaoshaMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

/**
 * @author yjw
 * @date 2022/3/20 17:17
 */
@Slf4j
@Component
public class ActivemqSender {

    @Autowired
    private JmsTemplate jmsTemplate;

    public void sendMiaoshaMsg(MiaoshaMessage miaoshaMessage){
        log.info("send miaosha msg ======================> {}",JSON.toJSONString(miaoshaMessage));
        jmsTemplate.convertAndSend(ActivemqConfig.MIAOSHA_ORDER_TOPIC, JSON.toJSONString(miaoshaMessage));
    }

    /**
     * 延时发送消息
     */
    public void scheduleSendOrderMsg(Long orderId, Long delay) {
        log.info("send delay order ====================> {} ", orderId);
        jmsTemplate.convertAndSend(ActivemqConfig.DELAY_ORDER_TOPIC, orderId,
                new ScheduleMessagePostProcesser(delay));
    }


}
